package com.danco.planner.view.core;

import com.danco.planner.supportclasses.enumeration.IEventType;
import com.danco.planner.view.interfaces.IEventListener;

public class AbstractButton extends AbstractLabel {

	protected String targetCommand;
	public String getTargetCommand() {
		return targetCommand;
	}
	public void setTargetCommand(String command) {
		this.targetCommand = command;
	}

	
	public AbstractButton() {
		this("");
	}
	public AbstractButton(String text) {
		this(text, null);
	}
	public AbstractButton(String text, String targetCommand) {
		
		this(text, targetCommand, null);
	}
	public AbstractButton(String text, String targetCommand, IEventType type) {
		
		super(text, type);
		setTargetCommand(targetCommand);
	}

	@Override
	public void doCustomActionWithType(IEventType type, String targetCommand) {

		touchButtonWithCommand(targetCommand,type);
		
		for (View view : subviews) {
			view.doActionWithType(type, targetCommand);
		}
	}
	
	public void touchButtonWithCommand(String command, IEventType eventType) {
		
		if (this.targetCommand.equalsIgnoreCase(command)) {
			for (IEventListener eventListener : listeners) {
				eventListener.handleAction(this, targetEventType);
			}
		}
	}

}
